package com.gzpi.hwgggh.sysenum;

/**
 * @date : 2020-12-21 09:14
 **/
public enum EnumErrorCode {

    SUCCESS_MESSAGE("000", "{0}"),
    ERROR_MESSAGE("1001", "{0}"),

    ERROR_OBJECT_ADD("201", "添加对象失败:{0}"),
    ERROR_OBJECT_EDIT("202", "添加编辑失败:{0}"),
    ERROR_OBJECT_DELETE("203", "添加删除失败:{0}"),
    ERROR_OBJECT_SEARCH("204", "查询对象失败:{0}"),
    ERROR_OBJECT_NULL("205", "对象ISNULL:{0}"),


    ERROR_SYSTEM_UNKNOWN("999", "程序异常:未知错误!");



    private String code;
    private String message;

    private EnumErrorCode(String value, String desc) {
        this.setCode(value);
        this.setMessage(desc);

    }


    public String getCode() {
        return code;
    }


    public void setCode(String code) {
        this.code = code;
    }


    public String getMessage() {
        return message;
    }


    public void setMessage(String message) {
        this.message = message;
    }


    @Override
    public String toString() {

        return "{\"code\":\""+this.code+"\",\"message\":\""+this.message+"\"}";
    }

    public String toString(String message) {
        if (this.message.contains("{0}")){
            this.message=this.message.replace("{0}", message);
        }else {
            if (this.message.indexOf(":")>-1){
               this.message = this.message.substring(0,this.message.indexOf(":")+1)+message;
            }else{
                this.message=message;
            }
        }

        return this.toString();
    }

}
